package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author huangxin
 * @description
 * @date 2020/12/2
 */
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerDao customerDao;

    @Override
    public PageInfo<Customer> getCustomersByPageAndCondition(String customerName) {
        List<Customer> customerList = customerDao.queryAllCustomersByCondition(customerName);
        return new PageInfo<>(customerList);
    }

    @Override
    public void saveCustomer(Customer customer) {
        customerDao.saveCustomer(customer);
    }

    @Override
    public void updateCustomerById(Customer customer) {
        customerDao.updateCustomerById(customer);
    }

    @Override
    public void deleteCustomersBatch(String ids) {
        String[] split = ids.split(",");
        List<String> idList = Arrays.stream(split).collect(Collectors.toList());
        customerDao.deleteCustomersBatch(idList);
    }

    @Override
    public List<Map<String, Object>> getAllCustomers() {
        return customerDao.getAllCustomers();
    }
}
